package com.jfs.qy.chain.component;

import com.jfs.qy.chain.AbstractServerStartHandler;
import com.jfs.qy.config.component.ProcessAlarmTask;
import com.jfs.qy.config.component.TaskExecutorReactor;
import com.jfs.qy.service.SystemSearchAlarmRtspUrlService;
import com.jfs.qy.template.S3Template;
import com.jfs.qy.utils.SystemCommonUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

/**
 * @Description 处理告警事件责任链
 * @E-mail cwm3412638@163.com
 * @Author cwm
 * @Date 2022/11/5
 */
@Component(value = ProcessAlarmEventComponent.BEAN_NAME)
public class ProcessAlarmEventComponent extends AbstractServerStartHandler {
    public final static String BEAN_NAME = "processAlarmEventComponent";
    private final TaskExecutorReactor taskExecutorReactor;
    private final SystemCommonUtils systemCommonUtils;
    private final SystemSearchAlarmRtspUrlService systemSearchAlarmRtspUrlService;
    private final S3Template s3Template;
    private final RabbitTemplate rabbitTemplate;

    public ProcessAlarmEventComponent(TaskExecutorReactor taskExecutorReactor,
                                      SystemCommonUtils systemCommonUtils,
                                      SystemSearchAlarmRtspUrlService systemSearchAlarmRtspUrlService,
                                      S3Template s3Template,
                                      RabbitTemplate rabbitTemplate) {
        this.taskExecutorReactor = taskExecutorReactor;
        this.systemCommonUtils = systemCommonUtils;
        this.systemSearchAlarmRtspUrlService = systemSearchAlarmRtspUrlService;
        this.s3Template = s3Template;
        this.rabbitTemplate=rabbitTemplate;
    }

    @Override
    public void handlerOperation() {
        //启用处理告警事件线程任务
        ProcessAlarmTask processAlarmTask = new ProcessAlarmTask(systemSearchAlarmRtspUrlService, systemCommonUtils,s3Template,rabbitTemplate);
        for (int i = 0; i <= systemCommonUtils.getRecordAlarmThread(); i++) {
            taskExecutorReactor.schedule(processAlarmTask, 0, systemCommonUtils.getProcessAlarmInterval());
        }
    }
}
